home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
bc_ti.zip
/
TI649.ASC
< prev
next >
Wrap
Text File
|
1992-02-25
|
14KB
|
463 lines
PRODUCT : Borland C++ NUMBER : 649
VERSION : 2.0
OS : PC DOS
DATE : February 25, 1992 PAGE : 1/7
TITLE : Common Causes of General Protection Faults
WHAT? GENERAL PROTECTION ERROR!
Protected mode development tools permit much larger programs to
be compiled faster than their real mode counterparts. They
accomplish this by allowing the use of a vastly larger memory
area than is available to real mode tools. There is a cost for
this increased capability, however; many of us will have to
change the coding practices and strategies we grew to depend on
with the relatively tolerant real mode development tools.
Central to this change is the increasingly notorious "General
Protection Fault." A GP Fault is generated by what one might
think of as a debugger built into the CPU and is enabled any time
a program is operating in protected mode. This debugger-in-a-CPU
is very, very uncompromising with regard to the rules which a
program must obey while availing itself of protected mode
capabilities.
For example, suppose a block of memory is allocated for use.
Further suppose that we code an errant read or write outside this
block. In real mode this may show up in a variety of more-or-
less unacceptable ways; many of these we can choose to ignore.
The same program executed in protected mode will, in all
probably, display a General Protection Fault error message and
immediately exit to DOS. This illustrates the cost of operating
in protected mode; our right to ignore coding problems is
seriously limited.
There is an upside to this, however: any program that runs for
any length of time in protected mode is likely to be far more bug
free than an equivalent program executed only in real mode.
General Protection Faults are generated, however, by more than
just reads or writes outside proper memory areas.
The following list, extracted from the Intel 386 Programmer's
Reference Manual, serves to suggest the level of "protection"
which we may expect while operating in protected mode:
-----------------------------------------------------------------------
PRODUCT : Borland C++ NUMBER : 649
VERSION : 2.0
OS : PC DOS
DATE : February 25, 1992 PAGE : 2/7
TITLE : Common Causes of General Protection Faults
All protection violations which do not cause another exception
cause a General-Protection Fault. This includes (but is not
limited to):
a. Exceeding the segment limit when using CS, DS, ES, FS, or GS
segments
b. Exceeding the segment limit when referencing a descriptor
table
c. Transferring execution to a segment which is not executable
d. Writing to a read-only data segment or a code segment
e. Reading from an execute-only code segment
f. Loading the SS register with a selector for a read-only
segment (unless the selector comes from a TSS during a task
switch, in which case an invalid-TSS exception occurs)
g. Loading the SS, DS, ES, FS, or GS register with a selector
for a system segment
h. Loading the DS, ES, FS, or GS register with a selector for an
execute-only code segment
i. Loading the SS register with the selector of an executable
segment
j. Accessing memory using the DS, ES, FS, or GS register when it
contains a null selector
k. Switching to a busy task
l. Violating privilege rules
m. Exceeding the instruction length limit of 15 bytes (this only
can occur when redundant prefixes are placed before an
instruction)
n. Loading the CRO register with a set PG bit (paging enabled)
and a clear PE bit (protection disabled)
PRODUCT : Borland C++ NUMBER : 649
VERSION : 2.0
OS : PC DOS
DATE : February 25, 1992 PAGE : 3/7
TITLE : Common Causes of General Protection Faults
o. Interrupt or exception through an interrupt or trap gate from
virtual-8086 mode to a handler at a privilege level other
than 0
p. The general-protection exception is a fault. In response to a
general-protection exception, the processor pushes an error
code onto the exception handler's stack. If loading a
descriptor causes the exception, the error code contains a
selector to the descriptor; otherwise, the error code is
null. The source of the selector in an error code may be any
of the following:
1. An operand of the instruction
2. A selector from a gate which is the operand of the
instruction
3. A selector from a TSS involved in a task switch
-----------------------------------------------------------------------
PROGRAM OR DEVELOPMENT TOOL?
Obviously if your applications are going to be subject to GP
Fault errors it stands to reason that the development tools
themselves must abide by the same rules and are subject to this
demanding debugger-in-a-CPU.
It is unlikely that any significant program has ever been bug-
free and Borland's development tools are no different. As you
might expect, we are dedicated to eliminating any bugs that can
be identified. One might guess that this would be an easy task.
Unfortunately the protected mode mechanism does not distinguish
between problems in the code being developed under the tools and
problems with the tools themselves. Consequently, it becomes
necessary for the developer to take additional steps to assure
that their code is not the cause. Although there is little that
Borland can do to make this process easier, we can supply you
with a list of known problems in the BC++ tools that generate
reproducible GP Fault errors. If you find a problem you are
encountering on this list you can eliminate your program as the
culprit.
PRODUCT : Borland C++ NUMBER : 649
VERSION : 2.0
OS : PC DOS
DATE : February 25, 1992 PAGE : 4/7
TITLE : Common Causes of General Protection Faults
- Moving the mouse while BCX is setting up to run your
program can cause a GP Fault. This can happen if the
mouse is moving when BCX switches from compiling to
linking also but not nearly as often as choosing RUN|RUN
and moving the mouse after the link or dependency check.
- Window Resize/Move- Clicking the mouse almost anywhere
outside of a BCX window set up for resizing or moving
(green bordered)
- Using the ,m (memory dump) option in a BCX watch window
- Doing a Repaint Desktop in BCX with a HERCULES card
attached (and any video cards doing Hercules simulation)
- Compiling a program under BCX using the ternary operator
with the second or third variables undefined
- Compiling a program with the OPTIONS|DIRECTORY|INCLUDE box
filled to its maximum
- Inspecting on a static member of a class with the BCX
debugger
- Compiling the DLLDEMO examples program under BCX using
different segment names for BSS or DATA
Ok, so the problem can't be in your application because you have
reduced it to the point where all it does is print "Hello, world"
and it's still giving you a GP Fault; and it's not on the list of
known problems.
There are two final sources of General Protection Faults that
have little to do with either the tools or the application under
dev